package com.aijk.ehm.service;

import com.aijk.base.entity.PagingRequest;
import com.aijk.commons.utils.Utils;

import com.aijk.ehm.dao.mybatis.EhmProblemLogMapper;
import com.aijk.ehm.model.EhmProblemLog;
import com.aijk.ehm.model.EhmProblemLogExample;
import com.aijk.ehm.model.qo.EhmProblemLogQo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EhmProblemLogService {
    private static Logger logger = LoggerFactory.getLogger(EhmProblemLogService.class);

    @Autowired
    private EhmProblemLogMapper mapper;

    public EhmProblemLogExample getExample(EhmProblemLogQo qo) {
        EhmProblemLogExample example = new EhmProblemLogExample();
        EhmProblemLogExample.Criteria criteria = example.createCriteria();
        if (qo != null) {
            if (Utils.isNotEmpty(qo.getSortway())) example.setOrderByClause(qo.getSortway());
            if(qo.getRidIsNotNull()!=null && !qo.getRidIsNotNull().equals("")) criteria.andRidIsNotNull();
            if(qo.getRidIsNull()!=null && !qo.getRidIsNull().equals("")) criteria.andRidIsNull();
            if(Utils.isNotEmpty(qo.getRid())) criteria.andRidEqualTo(qo.getRid());
            if(Utils.isNotEmpty(qo.getCompanyId())) criteria.andCompanyIdEqualTo(qo.getCompanyId());
            if(Utils.isNotEmpty(qo.getUid())) criteria.andUidEqualTo(qo.getUid());
            if(Utils.isNotEmpty(qo.getProblemTitle())) criteria.andProblemTitleEqualTo(qo.getProblemTitle());
        }
        return example;
    }

    public int count(EhmProblemLogQo qo) {
        return mapper.countByExample(getExample(qo));
    }

    public int save(EhmProblemLog bean) {
        return mapper.insertSelective(bean);
    }

    public int delete(Long id) {
        return mapper.deleteByPrimaryKey(id);
    }

    public int update(EhmProblemLog bean) {
        return mapper.updateByPrimaryKeySelective(bean);
    }

    public EhmProblemLog findOne(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    public List<EhmProblemLog> find(EhmProblemLogQo qo) {
        return mapper.selectByExample(getExample(qo));
    }

    public PageInfo<EhmProblemLog> page(PagingRequest pagingRequest, EhmProblemLogQo qo) {
        PageHelper.startPage(pagingRequest.getPageNum() , pagingRequest.getPageSize());
        return new PageInfo<EhmProblemLog>(mapper.selectByExample(getExample(qo)));
    }
}